package com.cskaoyan.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 创建日期: 2023/01/07 14:42
 *
 * @author ciggar
 */
@Configuration
public class MyGatewayConfig {

    @Bean
    public RouteLocator myRouteLocator(RouteLocatorBuilder builder){

        // 1. 获取所有的路由规则 routes
        RouteLocatorBuilder.Builder routes = builder.routes();

        // 2. 给routes中配置一个路由规则
        RouteLocator routeLocator = routes.route("code-route", predicateSpec -> predicateSpec
                .path("/code/route")
                .uri("http://localhost:9999")
        ).build();

        return routeLocator;

    }
}
